package com.itheima.user.controller;

import com.itheima.entity.dto.UserDto;
import com.itheima.entity.vo.RecommendVo;
import com.itheima.entity.vo.Result;
import com.itheima.entity.vo.UserVo;
import com.itheima.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :WuJunJie
 * packageName :com.itheima.user.controller
 * fileName :UserController
 * creationTime :2022-12-10 19:04
 */

@RestController
@RequestMapping("/userService/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody UserDto userDto) {
        UserVo login = userService.login(userDto);
        return Result.success(login);
    }

    @PostMapping("/sendMessage")
    public Result sendMessage(@RequestBody UserDto userDto) {
        Boolean aBoolean = userService.sendMessage(userDto);
        if (aBoolean) {
            return Result.success();
        }
        return Result.error();
    }

    @PutMapping("/updateInfo")
    public Result updateInfo(@RequestBody UserDto userDto) {
        Boolean update = userService.updateInfo(userDto);
        if (update) {
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("/verify")
    public Result verifyUpdatePhoneMessage(@RequestBody UserDto userDto) {
        Boolean update = userService.verifyUpdatePhoneMessage(userDto);
        if (update) {
            return Result.success();
        }
        return Result.error();
    }

    @PutMapping("/updatePhone")
    public Result updatePhone(@RequestBody UserDto userDto) {
        Boolean update = userService.updatePhone(userDto);
        if (update) {
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping("/recommend")
    public Result selectRecommend(@RequestParam(name = "longitude")Double longitude,
                            @RequestParam(name="latitude")Double latitude){
        List<RecommendVo> recommend=userService.selectRecommend(longitude,latitude);
        return Result.success(recommend);
    }




}
